//2009/08/28 10:53:35
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class TheLargestLuckyNumber
{
public:
    int find(int n)
    {
        for (int i=n; ; i--)
            if (islucky(i))
                return i;
    }
    bool islucky(int n)
    {
        while (n>0)
        {
            int a = n % 10;
            if (a!=4 && a!=7) return false;
            n /= 10;
        }
        return true;
    }
};
